/*
 * Created by SharpDevelop.
 * User: nebulom
 * Date: 8/26/2009
 * Time: 8:00 AM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Collections.Generic;

namespace Miming.Model
{
	/// <summary>
	/// Description of SalesOrder.
	/// </summary>
	public class SalesOrder
	{
		int id;
		string memo;
		
		public virtual string Memo {
			get { return memo; }
			set { memo = value; }
		}
		IList<SalesOrderItem> items = new List<SalesOrderItem>();
		
		public virtual IList<SalesOrderItem> Items {
			get { return items; }
			set { items = value; }
		}
		
		public virtual int Id {
			get { return id; }
			set { id = value; }
		}
		Customer customer;
		
		public virtual Customer Customer {
			get { return customer; }
			set { customer = value; }
		}
		DateTime date = DateTime.Now;
		
		public virtual DateTime Date {
			get { return date; }
			set { date = value; }
		}
		Class _class;
		
		public virtual Class Class {
			get { return _class; }
			set { _class = value; }
		}
		string sONo;
		
		public virtual string SONo {
			get { return sONo; }
			set { sONo = value; }
		}
		string pONo;
		
		public virtual string PONo {
			get { return pONo; }
			set { pONo = value; }
		}
		string nameAddress;
		
		public virtual string NameAddress {
			get { return nameAddress; }
			set { nameAddress = value; }
		}
		string shipTo;
		
		public virtual string ShipTo {
			get { return shipTo; }
			set { shipTo = value; }
		}
		CustomerMessage customerMessage;
		
		public virtual CustomerMessage CustomerMessage {
			get { return customerMessage; }
			set { customerMessage = value; }
		}
		Item taxItem;
		
		public virtual Item TaxItem {
			get { return taxItem; }
			set { taxItem = value; }
		}
		SalesTaxCode customerTaxCode;
		
		public virtual SalesTaxCode CustomerTaxCode {
			get { return customerTaxCode; }
			set { customerTaxCode = value; }
		}
		
		public SalesOrder()
		{
		}
		
		public virtual void AddItem(SalesOrderItem item)
		{
			item.Order = this;
			items.Insert(0, item);
			OnItemAdded(null);
		}
		
		protected virtual void OnItemAdded(EventArgs e)
		{
			if (ItemAdded != null) {
				ItemAdded(this, e);
			}
		}
		
		public virtual event EventHandler ItemAdded;
	}
	
	public class SalesOrderItem
	{
		Item item;
		
		public Item Item {
			get { return item; }
			set { item = value; }
		}
		SalesOrder order;
		
		public SalesOrder Order {
			get { return order; }
			set { order = value; }
		}
		double quantity;
		
		public double Quantity {
			get { return quantity; }
			set { quantity = value; }
		}
		
		public SalesOrderItem()
		{
		}
		
		public SalesOrderItem(Item item) : this(item, 1)
		{
		}
		
		public SalesOrderItem(Item item, double quantity)
		{
			this.item = item;
			this.quantity = quantity;
		}
	}
}
